package cn.wubo.vrr.help.service.impl;

import cn.wubo.vrr.help.entity.BaseInfo;
import cn.wubo.vrr.help.repository.BaseInfoRepo;
import cn.wubo.vrr.help.service.BaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class BaseInfoServiceImpl implements BaseInfoService {
    @Autowired
    BaseInfoRepo baseInfoRepo;

    @Override
    public BaseInfo saveOrUpdate(BaseInfo bi) {

        BaseInfo query = new BaseInfo();
        query.setEMPLID(bi.getEMPLID());
        Optional<BaseInfo> one = baseInfoRepo.findOne(Example.of(query));

        if (one.isPresent()) {
            bi.setId(one.get().getId());
            bi = baseInfoRepo.saveAndFlush(bi);
        } else
            bi = baseInfoRepo.save(bi);

        return bi;
    }
}
